package com.ffcc.fitness.websocket.config;

import com.ffcc.fitness.websocket.handler.SpringChatWebSocketHandler;
import com.ffcc.fitness.websocket.handler.SpringWebSocketHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

/**
 * Spring WebSocket配置类
 */
@Configuration
@EnableWebSocket
public class SpringWebSocketConfig implements WebSocketConfigurer {

    @Autowired
    private SpringChatWebSocketHandler springChatWebSocketHandler;    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        // 注册测试WebSocket处理器
        registry.addHandler(new SpringWebSocketHandler(), "/websocket/spring/{userId}")
                .setAllowedOrigins("*"); // 允许跨域
        
        // 注册聊天WebSocket处理器
        registry.addHandler(springChatWebSocketHandler, "/websocket/chat/{userId}")
                .setAllowedOrigins("*"); // 允许跨域
        
        System.out.println("=== Spring WebSocket端点已注册: /websocket/spring/{userId} (测试) ===");
        System.out.println("=== Spring WebSocket端点已注册: /websocket/chat/{userId} (聊天) ===");
    }
}
